CC=gcc
CXX=g++

mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(dir $(mkfile_path))

APP_SRC_DIR=$(mkfile_dir)../..
TEST_SRC_DIR=.

APP_CFLAGS=-fprofile-arcs -ftest-coverage -I$(APP_SRC_DIR)/mmkv_cpp/include -I$(APP_SRC_DIR)/mmkv_cpp
TEST_CFLAGS=-I$(APP_SRC_DIR)/mmkv_cpp/include -I$(APP_SRC_DIR)/mmkv_cpp -w
APP_LDFAGS=-L$(APP_SRC_DIR)/lib -lcore -lgcov -lpthread -Wl,-rpath=$(APP_SRC_DIR)/lib

APP_SRC=native-mmkv.cpp
APP_OBJ=$(addprefix build/, $(APP_SRC:.cpp=.o))

TEST_SRC=main-ut.cpp native-mmkv-ut.cpp
TEST_OBJ=$(addprefix build/, $(TEST_SRC:.cpp=.o))

all: clean build/mmkv
	(cd build; ./mmkv)
	lcov -b build -d build -c -o build/mmkv.info
	mkdir -p build/lcov
	lcov --remove build/mmkv.info '*/include/*' -o build/mmkv.info
	genhtml -o build/lcov build/mmkv.info
build/%.o: $(TEST_SRC_DIR)/%.cpp
	$(CXX) -o $@ $^ -c $(TEST_CFLAGS)
build/%.o: $(APP_SRC_DIR)/mmkv_cpp/%.cpp
	$(CXX) -o $@ $^ -c $(APP_CFLAGS)
build/mmkv: $(APP_OBJ) $(TEST_OBJ)
	$(CXX) -o $@ $^ $(APP_LDFAGS)

clean:
	rm -rf build
	mkdir -p build

.PHONY: all clean